package seven.test_7_18;

public class Solution {
    public int getLongestPalindrome(String A) {
        // write code here
        int max = 0;
        int left = 0;
        int right = 0;
        for (int i = 0; i < A.length(); i++) {
            int len = 1;
            left = i - 1;
            right = i + 1;
            while (left > 0 && A.charAt(i) == A.charAt(left)) {
                left--;
                len++;
            }
            while (right < A.length() && A.charAt(i) == A.charAt(right)) {
                right++;
                len++;
            }
            while (left > 0 && right < A.length() && A.charAt(left) == A.charAt(right)) {
                left--;
                right++;
                len += 2;
            }
            max = Math.max(len, max);
        }
        return max;
    }
}

